package admin.controllers;

import helpers.IdUniqueHelper;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.CooperationModel;

import admin.data.CooperationData;

public class ViewCooperationServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		String path = ((HttpServletRequest) request).getRequestURI();
		String id = "";
		try {
			id = URLDecoder.decode(path.replaceAll("/admin/cooperation/read/", ""),"UTF-8");
		} catch (Exception e) {
			response.sendRedirect("/admin/cooperation/list");
		}
		
		CooperationData cooperationData = new CooperationData();
		CooperationModel cooperation = cooperationData.getCooperation(id);
		
		request.setAttribute("form", "view");
		request.setAttribute("cooperation", cooperation);
		try {
			request.getRequestDispatcher("/admin/pages/view_cooperation.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
